home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / bxor.c < prev    next >
C/C++ Source or Header  |  1990-10-12  |  4KB  |  161 lines

  1. /* 
  2.  * xor.c --
  3.  *
  4.  * Copyright 1990 Regents of the University of California
  5.  * Permission to use, copy, modify, and distribute this
  6.  * software and its documentation for any purpose and without
  7.  * fee is hereby granted, provided that the above copyright
  8.  * notice appear in all copies.  The University of California
  9.  * makes no representations about the suitability of this
  10.  * software for any purpose.  It is provided "as is" without
  11.  * express or implied warranty.
  12.  */
  13.  
  14. #ifndef lint
  15. static char rcsid[] = "$Header: /sprite/src/kernel/raid/RCS/bxor.c,v 1.3 90/10/12 14:00:47 eklee Exp $ SPRITE (Berkeley)";
  16. #endif /* not lint */
  17.  
  18. #include "machparam.h"
  19.  
  20.  
  21. /*
  22.  *----------------------------------------------------------------------
  23.  *
  24.  * Xor2 --
  25.  *
  26.  *    *destBuf ^= *srcBuf;
  27.  *    Modified from bcopy.
  28.  *
  29.  * Results:
  30.  *      *destBuf.
  31.  *
  32.  * Side effects:
  33.  *    None.
  34.  *
  35.  *----------------------------------------------------------------------
  36.  */
  37.  
  38. #define WORDMASK WORD_ALIGN_MASK
  39.  
  40. void
  41. Xor2(numBytes, sourcePtr, destPtr)
  42.     char *sourcePtr;        /* Where to copy from */
  43.     char *destPtr;        /* Where to copy to */
  44.     register int numBytes;    /* The number of bytes to copy */
  45. {
  46.     register int *sPtr = (int *) sourcePtr;
  47.     register int *dPtr = (int *) destPtr;
  48.  
  49.     /*
  50.      * If the destination is below the source then it is safe to copy
  51.      * in the forward direction.  Otherwise, we must start at the top
  52.      * and work down, again optimizing for large transfers.
  53.      */
  54.  
  55.     if (dPtr < sPtr) {
  56.     /*
  57.      * If both the source and the destination point to aligned
  58.      * addresses then copy as much as we can in large transfers.  Once
  59.      * we have less than a whole int to copy then it must be done by
  60.      * byte transfers.  Furthermore, use an expanded loop to avoid
  61.      * the overhead of continually testing loop variables.
  62.      */
  63.     
  64.     if (!((((int) sPtr) | (int) dPtr) & WORDMASK)) {
  65.         while (numBytes >= 16*sizeof(int)) {
  66.         dPtr[0] ^= sPtr[0];
  67.         dPtr[1] ^= sPtr[1];
  68.         dPtr[2] ^= sPtr[2];
  69.         dPtr[3] ^= sPtr[3];
  70.         dPtr[4] ^= sPtr[4];
  71.         dPtr[5] ^= sPtr[5];
  72.         dPtr[6] ^= sPtr[6];
  73.         dPtr[7] ^= sPtr[7];
  74.         dPtr[8] ^= sPtr[8];
  75.         dPtr[9] ^= sPtr[9];
  76.         dPtr[10] ^= sPtr[10];
  77.         dPtr[11] ^= sPtr[11];
  78.         dPtr[12] ^= sPtr[12];
  79.         dPtr[13] ^= sPtr[13];
  80.         dPtr[14] ^= sPtr[14];
  81.         dPtr[15] ^= sPtr[15];
  82.         sPtr += 16;
  83.         dPtr += 16;
  84.         numBytes -= 16*sizeof(int);
  85.         }
  86.         while (numBytes >= sizeof(int)) {
  87.         *dPtr++ ^= *sPtr++;
  88.         numBytes -= sizeof(int);
  89.         }
  90.         if (numBytes == 0) {
  91.         return;
  92.         }
  93.     }
  94.     
  95.     /*
  96.      * Copy the remaining bytes.
  97.      */
  98.     
  99.     sourcePtr = (char *) sPtr;
  100.     destPtr = (char *) dPtr;
  101.     while (numBytes > 0) {
  102.         *destPtr++ ^= *sourcePtr++;
  103.         numBytes--;
  104.     }
  105.     } else {
  106.     /*
  107.      * Handle extra bytes at the top that are due to the transfer
  108.      * length rather than pointer misalignment.
  109.      */
  110.     while (numBytes & WORDMASK) {
  111.         numBytes --;
  112.         destPtr[numBytes] ^= sourcePtr[numBytes];
  113.     }
  114.     sPtr = (int *) (sourcePtr + numBytes);
  115.     dPtr = (int *) (destPtr + numBytes);
  116.  
  117.     if (!((((int) sPtr) | (int) dPtr) & WORDMASK)) {
  118.         while (numBytes >= 16*sizeof(int)) {
  119.         sPtr -= 16;
  120.         dPtr -= 16;
  121.         dPtr[15] ^= sPtr[15];
  122.         dPtr[14] ^= sPtr[14];
  123.         dPtr[13] ^= sPtr[13];
  124.         dPtr[12] ^= sPtr[12];
  125.         dPtr[11] ^= sPtr[11];
  126.         dPtr[10] ^= sPtr[10];
  127.         dPtr[9] ^= sPtr[9];
  128.         dPtr[8] ^= sPtr[8];
  129.         dPtr[7] ^= sPtr[7];
  130.         dPtr[6] ^= sPtr[6];
  131.         dPtr[5] ^= sPtr[5];
  132.         dPtr[4] ^= sPtr[4];
  133.         dPtr[3] ^= sPtr[3];
  134.         dPtr[2] ^= sPtr[2];
  135.         dPtr[1] ^= sPtr[1];
  136.         dPtr[0] ^= sPtr[0];
  137.         numBytes -= 16*sizeof(int);
  138.         }
  139.         while (numBytes >= sizeof(int)) {
  140.         *--dPtr ^= *--sPtr;
  141.         numBytes -= sizeof(int);
  142.         }
  143.         if (numBytes == 0) {
  144.         return;
  145.         }
  146.     }
  147.     
  148.     /*
  149.      * Copy the remaining bytes.
  150.      */
  151.     
  152.     destPtr = (char *) dPtr;
  153.     sourcePtr = (char *) sPtr;
  154.     while (numBytes > 0) {
  155.         *--destPtr ^= *--sourcePtr;
  156.         numBytes--;
  157.     }
  158.     }
  159. }
  160.  
  161.